<template>
    <div class="top">
        <div class="left">
            <span class="lbtn" @click="goHome">首页</span>
        </div>
        <div class="center">
            <div class="title">旅游大数据可视化平台</div>
        </div>
        <div class="right">
            <span class="rbtn">统计报告</span>
            <span class="time">当前时间:{{ time }}</span>
        </div>
    </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from 'vue'
import { useRouter } from 'vue-router'
//引入自动计时插件
import moment from 'moment'

let $router = useRouter()
//存储当前时间
let time = ref(moment().format('YYYY年MM月DD日-hh:mm:ss'))
//定义一个定时器对象
let timer = ref(0)

//首页按钮点击回调
let goHome = () => {
    $router.push('/home')
}

onMounted(() => {
    timer.value = setInterval(() => {
        time.value = moment().format('YYYY年MM月DD日-hh:mm:ss')
    }, 1000)
})
onBeforeUnmount(() => {
    clearInterval(timer.value)
})
</script>

<style scoped lang="scss">
.top {
    width: 100%;
    height: 42px;
    display: flex;

    .left {
        flex: 563.5;
        background: url(../../images/dataScreen-header-left-bg.png) no-repeat;
        background-size: 100% 100%;

        .lbtn {
            width: 135px;
            height: 42px;
            float: right;
            background: url(../../images/dataScreen-header-btn-bg-l.png) no-repeat;
            background-size: cover;
            text-align: center;
            line-height: 42px;
            color: #29fcff;
        }

        .lbtn:hover {
            cursor: pointer;
        }
    }

    .center {
        flex: 793;

        .title {
            width: 100%;
            height: 74px;
            background: url(../../images/dataScreen-header-center-bg.png) no-repeat;
            background-size: cover;
            text-align: center;
            line-height: 74px;
            color: #29fcff;
            font-size: 36px;
        }
    }

    .right {
        flex: 563.5;
        background: url(../../images/dataScreen-header-right-bg.png) no-repeat;
        background-size: 100% 100%;

        .rbtn {
            width: 135px;
            height: 42px;
            float: left;
            background: url(../../images/dataScreen-header-btn-bg-r.png) no-repeat;
            background-size: cover;
            text-align: center;
            line-height: 42px;
            color: #29fcff;
        }

        .rbtn:hover {
            cursor: pointer;
        }

        .time {
            width: 300px;
            height: 42px;
            float: right;
            text-align: center;
            line-height: 42px;
            color: #29fcff;
        }
    }
}
</style>